// Activating the ADC interrupts
void Analog_Init(void)
{
  // Set prescaler to 32, so ADC clock is now 500 KHz
  /*bitSet(ADCSRA, ADPS2);
   bitClear(ADCSRA, ADPS1);
   bitSet(ADCSRA, ADPS0);*/

  ADCSRA|=(1<<ADIE)|(1<<ADEN); // Enable interrupt and enable ADC
  MuxSel = 0;
  ADMUX = (analog_reference << 6) | MuxSel;  // Select channel MuxSel

    ADCSRA|= (1<<ADSC);  // Start the conversion
}

//ADC interrupt
ISR(ADC_vect)
{
  volatile byte low, high;
  low = ADCL;
  high = ADCH;

  ADC_raw[ADC_count] = (high << 8) | low;

  ADC_count++;

  if (ADC_count >= NBSAMPLE)
  {
    Serial.write(0xff); //start byte
    for (int i = 0; i< NBSAMPLE; i++)
    {
      Serial.write(ADC_raw[i]&0xff);  
      Serial.write((ADC_raw[i] >> 8)&0xff);  
      ADC_raw[i] = 0;
    }
    ADC_count = 0;
  }

  ADCSRA|= (1<<ADSC);  // Start the conversion
}






















